from rest_framework import serializers
from .models import User

class UserSerializer(serializers.HyperlinkedModelSerializer):
    class Meta:
        model = User
        fields = [
            'url',
            'id',
            'last_login',
            'username',
            'first_name',
            'last_name',
            'email',
            'date_joined',
            'title',
            'age',
        ]
    
    def create(self, validated_data):
        user=User(**validated_data)
        user.set_password("1234567890")
        user.save()
        return user
    
    def update(self, instance, validated_data):
        instance:User=super().update(instance, validated_data)
        return instance